#pragma once

#include "DestroyObjectAction.h"

#include "InputPin.h"

namespace uml {

const bool DestroyObjectAction::isDestroyLinks_default_ = false;
const bool DestroyObjectAction::isDestroyOwnedObjects_default_ = false;
DestroyObjectAction::DestroyObjectAction(const QString& umlType)
    : Action(umlType) {}

void DestroyObjectAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    isDestroyLinks_ = json.value("isDestroyLinks").toBool(isDestroyLinks_default_);
    isDestroyOwnedObjects_ = json.value("isDestroyOwnedObjects").toBool(isDestroyOwnedObjects_default_);
    target_ = JsonSerializable::create<InputPin>(json.value("target"), errorList);

}

void DestroyObjectAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (isDestroyLinks_ != isDestroyLinks_default_) {
        json.insert("isDestroyLinks", isDestroyLinks_);
    }
    if (isDestroyOwnedObjects_ != isDestroyOwnedObjects_default_) {
        json.insert("isDestroyOwnedObjects", isDestroyOwnedObjects_);
    }
    if (target_) {
        QJsonObject target_json;
        target_->toJson(target_json);
        json.insert("target", target_json);
    }
}

/// <summary>
/// isDestroyLinks getter
/// Specifies whether links in which the object participates are destroyed along
/// with the object.
/// </summary>
bool DestroyObjectAction::isDestroyLinks() const {
    return isDestroyLinks_;
}

/// <summary>
/// isDestroyLinks setter
/// Specifies whether links in which the object participates are destroyed along
/// with the object.
/// </summary>
void DestroyObjectAction::setIsDestroyLinks(bool value) {
    isDestroyLinks_ = value;
}

/// <summary>
/// isDestroyOwnedObjects getter
/// Specifies whether objects owned by the object (via composition) are destroyed
/// along with the object.
/// </summary>
bool DestroyObjectAction::isDestroyOwnedObjects() const {
    return isDestroyOwnedObjects_;
}

/// <summary>
/// isDestroyOwnedObjects setter
/// Specifies whether objects owned by the object (via composition) are destroyed
/// along with the object.
/// </summary>
void DestroyObjectAction::setIsDestroyOwnedObjects(bool value) {
    isDestroyOwnedObjects_ = value;
}

/// <summary>
/// target getter
/// The InputPin providing the object to be destroyed.
/// </summary>
shared_ptr<InputPin> DestroyObjectAction::target() const {
    return target_;
}

/// <summary>
/// target setter
/// The InputPin providing the object to be destroyed.
/// </summary>
void DestroyObjectAction::setTarget(shared_ptr<InputPin> value) {
    target_ = value;
}

} // namespace uml
